package vm

import (
	"bufio"
	"os"
)

const MEMORY_MAX int = 1 << 16
const (
	MR_KBSR uint16 = 0xFE00
	MR_KBDR uint16 = 0xFE02
)

var memory [MEMORY_MAX]uint16

func MemoryWrite(address uint16, val uint16) {
	memory[address] = val
}

func MemoryRead(address uint16) uint16 {
	if address == MR_KBSR {
		char, _, _ := bufio.NewReader(os.Stdin).ReadRune()
		memory[MR_KBSR] = 1 << 15
		memory[MR_KBDR] = uint16(char)
	}
	return memory[address]
}
